﻿<script setup lang="ts">
import { getAllDep } from '@/services/consult';
import { useConsultStore } from '@/stores/modules/consult';
import type { TopDep } from '@/types/consult';
import { computed, ref } from 'vue'

const active = ref(0) // 记录当前选中
const topDep=ref<TopDep[]>([])
getAllDep().then(res=>{
  topDep.value=res.data
})
const consultStore = useConsultStore()
const subDep=computed(()=>{
  return topDep.value[active.value]?.child
})
</script>

<template>
  <div class="consult-dep-page">
    <!-- <cp-nav-bar title="选择科室" /> -->
    <div class="wrapper">
      <van-sidebar v-model="active">
        <van-sidebar-item v-for="item in topDep" :key="item.id" :title="item.name" />
      </van-sidebar>
      <div class="sub-dep">

        <router-link @click="consultStore.setDepId(sub.id)" v-for="sub in subDep" :key="sub.id" :to="`/consult/ill`">{{sub.name}}</router-link>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.van-sidebar {
  width: 114px;
  &-item {
    padding: 14px;
    color: var(--cp-tag);
    &--select {
      color: var(--cp-main);
      font-weight: normal;
      &::before {
        display: none;
      }
    }
  }
}
.consult-dep-page {
  padding-top: 46px;
  .wrapper {
    height: calc(100vh - 46px);
    overflow: hidden;
    display: flex;
    .sub-dep {
      flex: 1;
      height: 100%;
      overflow-y: auto;
      > a {
        display: block;
        padding: 14px 30px;
        color: var(--cp-dark);
      }
    }
  }
}
</style>